import { Request, Response } from "express";
import { NextFunction } from "express-serve-static-core";
const express = require("express");
const router = express.Router();
import efetch from "../efetch";
import { isEmail, isDebug, isPhone } from "../../config";
import utils from "../../utils";
const request = require("request");
const rp = require("request-promise");
import jar from "../toughCookie";
import r from "../r";
import * as config from "../../config";

router.get("/", function(req: Request, res: Response, next: NextFunction) {});

//这里需要优化  进入接口 首先 批量删除 之前的code 避免冗余
router.get(
  "/:id/:type/:password",
  async (req: Request, res: Response, next: NextFunction) => {}
);

router.post("/", async (req: Request, res: Response, next: NextFunction) => {
  const { email, type } = req.body;
  try {
    const newurl = `${config.api}/emailCode/send`;

    const ret = await r(
      {
        url: newurl,
        body: JSON.stringify({
          email
        })
      },
      req,
      res
    );
    const jsonRet = JSON.parse(ret.body);

    res.json(jsonRet);
  } catch (e) {
    res.json({
      code: -1,
      data: undefined,
      msg: e
    });
  }
});

router.put("/:id", function(
  req: Request,
  res: Response,
  next: NextFunction
) {});

router.delete("/:id", function(
  req: Request,
  res: Response,
  next: NextFunction
) {});

export default router;
